<?php

class App_Methods_Data_UserExt extends App_Methods_Data_User {
	
	public $email;
	public $company;
	public $department;
	public $phone;
	public $mobile;
	public $photo;
	public $isActive;
	public $lastLogin;
	/**
	 * 
	 * @var App_Methods_Data_UserGroup
	 */
	public $group = null;
	
	public function __construct(Users $user, $withLastLogin=false) {
		parent::__construct($user);
		if ($withLastLogin) {
			$lastLogin = AuthHistoryQuery::create()
				->select('created')
				->filterByUsers($user)
				->offset(1)
				->orderByCreated(Criteria::DESC)
				->findOne();
			if ($lastLogin !== null) {
				$lastLogin = new DateTime($lastLogin);
				$lastLogin = $lastLogin->format('H:i:s d.m.Y');
			}
			$this->lastLogin = $lastLogin;
		}
		$this->email = $user->getEmail();
		$this->company = $user->getCompany();
		$this->department = $user->getDepartment();
		$this->phone = $user->getPhone();
		$this->mobile = $user->getMobile();
		$this->photo = $user->getPhoto();
		$this->isActive = (bool)$user->getActive();
		if ($user->getUserGroups() instanceof UserGroups)
			$this->group = new App_Methods_Data_UserGroup($user->getUserGroups());
	}
	
}